const PrerenderSPAPlugin = require('prerender-spa-plugin');
const Render = PrerenderSPAPlugin.PuppeteerRenderer;
const path = require('path');
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV)
module.exports = {
  // 基本路径
  publicPath: '/',
  // 输出文件目录
  outputDir: 'dist',
  configureWebpack: config => {
    if (IS_PROD) {
      return {
        plugins: [
          new PrerenderSPAPlugin({
            staticDir: path.join(__dirname, 'dist'),
            outputDir: path.join(__dirname, '/dist'),
            indexPath: path.join(__dirname, 'dist/index.html'),
            routes: ['/','/homepage','/archive','/type','/tag','/message','/introduce','/friend'],
            minify: {
              minifyCSS: true, // css压缩
              removeComments: true // 移除注释
            },
            render: new Render({
              inject: {
                foo: 'bar'
              },
              headless: false,
              renderAfterDocumentEvent: 'render-event'
            })
          })
        ]
      }
    }
  }
}
